package chapter5.section4;

import java.util.Date;

//程序5-9：一个记录每次交易细节的事务类
public class Transaction {
    public static final String[] types = {"存款", "取款", "查询", "转账"};
    public static final int TYPE_DEPOSIT = 0;
    public static final int TYPE_WITHDRAW = 1;
    public static final int TYPE_QUERY = 2;
    public static final int TYPE_TRANSFER = 3;
    private final int type;// 业务类型
    private Date createTime;// 业务发生时间
    private int amount;// 业务涉及的金额

    public Transaction(int type, int amount) {
        super();
        this.type = type;
        this.createTime = new Date();
        this.amount = amount;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    @Override
    public String toString() {
        return "Transaction[时间:" + createTime + ",业务类型：" + types[type] + ",金额" + amount + "]";
    }
}
